An inline function is a function which gets textually inserted by the compiler, much like a macro. Like macros, performance is improved by avoiding the overhead of the call itself, and (especially!) by the compiler being able to optimize *through* the call ('procedural integration'). Unlike macros, arguments to inline fns are always evaluated exactly once, so the 'call' is semantically like a regular function call only faster. Also unlike macros, argument types are checked and necessary conversions are performed correctly.
Beware that overuse of inline functions can cause code bloat, which can in turn have a negative performance impact in paging environments.
They are declared by using the 'inline' keyword when the function is defined:
inline void f(int i, char c) { /*...*/ } //an inline function
or by including the function definition itself within a class:
class X {
public:
void f(int i, char c) { /*...*/ } //inline function within a class
};
or by defining the member function as 'inline' outside the class:
class X {
public:
void f(int i, char c);
};
//...
inline void X::f(int i, char c) {/*...*/} //inline fn outside the class
Generally speaking, a function cannot be defined as 'inline' after it has been called. Inline functions should be defined in a header file, with 'outlined' functions appearing in a '.C' file (or .cpp, etc; see question on file naming conventions).